home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
127_01
/
rap4.c
< prev
next >
Wrap
Text File
|
1985-03-09
|
19KB
|
694 lines
/*********************************************************************\
** .---------------------------------------------------------------. **
** | | **
** | | **
** | Copyright (c) 1981, 1982, 1983 by Eric Martz. | **
** | | **
** | | **
** | Permission is hereby granted to use this source | **
** | code only for non-profit purposes. Publication of | **
** | all or any part of this source code, as well as | **
** | use for business purposes is forbidden without | **
** | written permission of the author and copyright | **
** | holder: | **
** | | **
** | Eric Martz | **
** | POWER TOOLS | **
** | 48 Hunter's Hill Circle | **
** | Amherst MA 01002 USA | **
** | | **
** | | **
** `---------------------------------------------------------------' **
\*********************************************************************/
#include "rap.h"
/*------------------------------------------------------------------------*/
init_ss() {
FILE *fpss;
int c, junk;
Ss_pair_cnt = 0;
Oldnewtot = 0;
/* GET STRINGS FROM SSn */
fpss = fopen(Ss_name,"r-");
if (!fpss) {
fprintf(STDERR,"Warning: file \"%s\" does not exist.\n",Ss_name);
return(0);
}
fprintf(STDERR,"Reading file \"%s\":\n",Ss_name);
/* PROCESS CONTENTS OF *.SS FILE */
/* ONLY BLANK LINES, COMMENTS ALLOWED BEFORE COMMANDS */
FOREVER {
c = getc(fpss);
switch (c) {
case '\n':
case '\r':
/* INGNORE BLANK LINES */
break;
case '!':
/* READ AND IGNORE REMAINDER OF LINE */
rapgets(Inbuf,fpss);
break;
case COMMAND:
ungetc(c,fpss);
rapgets(Inbuf,fpss);
de_comment(Inbuf);
command(Inbuf, Nxname, &junk);
break;
default:
goto pastcomms;
}
}
pastcomms:
if (c EQ EOF) c = CPMEOF;
ungetc(c,fpss);
/* GET SUBSTITUTION PAIRS AND HARDWARE INFO */
if (!getpairs(fpss, Ss_name)) {
fprintf(STDERR, "ERROR in SS file:\n");
fprintf(STDERR, " }u+}, }u-}, }b+}, or }b-} is missing.\n");
}
fpfree(fpss);
/* put "}RF}" in Oldstring[0] for use in ss() */
Inbuf[0] = Post_ss_delim;
Inbuf[1] = NULL;
strcat(Inbuf,"RF");
Inbuf[3] = Post_ss_delim;
Inbuf[4] = NULL;
Oldstring[0] = pack(Oldnewbuf,&Oldnewtot,MAXPACK,Inbuf);
}
/*------------------------------------------------------------------------*/
ss(bf,mark)
char *bf, *mark;
{
char double_delim[3], newrf[5], prompt[3], delim_str[2], wait[7];
char up[3], down[3], under[3], bold[3], arab[8];
int start, stop, i, pr;
delim_str[0] = *mark;
delim_str[1] = NULL;
wait[0] = Post_ss_delim;
wait[1] = NULL;
strcpy(wait, "wait");
wait[5] = Post_ss_delim;
wait[6] = NULL;
up[0] = down[0] = under[0] = bold[0] = Pre_ss_delim;
up[1] = 'u';
down[1] = 'd';
under[1] = '_';
bold[1] = '!';
up[2] = down[2] = under[2] = bold[2] = NULL;
#ifdef DEBUG
if (Debug) {
fprintf(STDERR,"Entering ss%s:",mark);
checkbig("",bf);
}
#endif
stop = 0;
/* CONVERT CONSOLE PROMPT DELIMITERS */
prompt[0] = Post_ss_delim;
prompt[1] = '"';
prompt[2] = NULL;
while (mark[0] EQ Post_ss_delim
AND (i = instr(0, bf, prompt)) NE ERROR) {
bf[i] = c1(PROMPT);
pr = i;
do { /* SHIFT DOWN TO DELETE " */
i++;
bf[i] = bf[i+1];
} while (bf[i]);
i = instr(pr, bf, delim_str);
if (i EQ ERROR) {
i = strlen(bf);
bf[i+1] = NULL;
}
bf[i] = c1(PROMPT);
}
/* SQUEEZE BLANKS OUT OF ORIGINAL STRINGS FOR SUBSTITUTION */
while ((start = instr(stop, bf, mark)) NE -1) {
stop = instr(start+1, bf, mark);
if (stop EQ -1) {
fprintf(STDERR,
"Incomplete \"%s\"-delimited substitution string at line %d:\n",
mark,In_linecnt);
checkbig("",bf);
exit(0);
}
stop = stop +1;
/* -(delchars(bf+start, bf+stop, " ")); defeated 2.21 */
}
#ifdef DEBUG
if (Debug AND stop NE 0) checkbig("",bf);
#endif
/* NO SUBSTITUTIONS NECESSARY */
/* IF \\ THEN SS IS NOT CALLED UNLESS \\ OR Press_all */
if (stop EQ 0 AND mark[0] EQ Post_ss_delim) return(0);
/* INSTALL AUTO-INCREMENTING ARABIC NUMBER IF NEEDED */
if (mark[0] EQ Pre_ss_delim) {
arab[0] = Pre_ss_delim;
arab[1] = '#';
arab[2] = NULL;
if ((i=instr(0, bf, arab)) NE ERROR) {
if (bf[i+2] EQ '+') Arabic++;
sprintf(newrf, "%d", Arabic);
arab[2] = '+';
arab[3] = Pre_ss_delim;
arab[4] = NULL;
if (bf[i+2] EQ '+') substitute(bf, arab, newrf);
else {
arab[2] = Pre_ss_delim;
arab[3] = NULL;
substitute(bf, arab, newrf);
}
}
}
/* EXPAND SUPERSCRIPT/SUBSCRIPT MACRO */
if (mark[0] EQ Pre_ss_delim) {
start = 0;
while ((start=instr(start,bf, up)) NE ERROR)
updown(bf,start,'u');
start = 0;
while ((start=instr(start,bf, down)) NE ERROR)
updown(bf,start,'d');
start = 0;
while ((start=instr(start,bf, under)) NE ERROR)
updown(bf,start,'_');
start = 0;
while ((start=instr(start,bf, bold)) NE ERROR)
updown(bf,start,'!');
}
/* WAIT */
if (mark[0] EQ Post_ss_delim) substitute(bf, wait, WAIT);
/* MAIN SUBSTITUTION LOOP */
for (i = 1; i <= Ss_pair_cnt; i++) {
if (*Oldstring[i] EQ mark[0]
OR
/* FOR NON-DELIMITED ORIGINAL STRINGS (WHICH MUST HAVE BEEN
SUFFIXED WITH '@' IN THE SSn FILE) */
(mark[0] EQ Pre_ss_delim
AND
*Oldstring[i] NE Post_ss_delim))
substitute (bf, Oldstring[i], Newstring[i]);
}
/* RESTORE FONT IF REQUESTED */
if (mark[0] EQ Post_ss_delim AND Font_o) {
sprintf(newrf, "%s%d%s", Font_o, Font, Font_c);
substitute(bf, Oldstring[0], newrf);
/* Oldstring[0] was initialized to "}RF}" in init_ss */
}
/* CONVERT }} TO } AND {{ TO { */
if (bf[0] NE COMMAND) {
double_delim[0] = double_delim[1] = mark[0];
double_delim[2] = NULL;
substitute (bf, double_delim, mark);
}
#ifdef DEBUG
if (Debug) checkbig("ss done:",bf);
#endif
}
/*------------------------------------------------------------------------*/
expantab(bf)
char *bf;
{
int b, t, inss, pos;
char tmp[BIGBUF];
/* IF THERE'S NO TAB, RETURN */
if ((b=instr(0,bf,"\t")) EQ -1) return(0);
/* IF THERE'S A TAB, TRANSFER PRE-TAB STRING TO TMP */
for (t=0, pos=0; t<b; t++, pos++) tmp[t] = bf[t];
t = b;
/* EXPAND TABS, TAKING POST-SUBSTITUTIONS INTO ACCOUNT */
inss = 0;
while (bf[b]) {
if (bf[b] NE TAB) {
if (bf[b] EQ Post_ss_delim) {
if (!inss) inss = YES; /* OPENING DELIM */
if (!inss) pos++;
if (inss) inss = NO; /* CLOSING DELIM */
}
else if (!inss) pos++;
tmp[t++] = bf[b++];
}
else {
do {
tmp[t++] = SPACE;
pos++;
} while (pos%Tabval);
b++;
}
}
tmp[t] = NULL;
strcpy(bf, tmp);
}
/*------------------------------------------------------------------------*/
/* FNNLGETS = File-No-NewLine-GET-String
SAME AS FGETS BUT STRING LEFT IN S IS STRIPPED OF THE TERMINAL NEWLINE.
RAPGETS: SETS Press_flg + FOR EVEN NUMBER OF Pre_ss_delim, - FOR ODD,
0 FOR NONE. */
rapgets(s,fp)
char *s;
FILE *fp;
{
char *p;
int length;
Press_flg = 0;
if ((length = biggets(s,fp)) EQ 0) return(0);
In_linecnt++;
if (Pre_ss) for(p = s; *p; p++) {
if (*p EQ Pre_ss_delim) {
if (Press_flg >= 0) Press_flg = -1;
else Press_flg = 1;
}
}
/* TRIMS OFF TERMINAL NEWLINE */
if (s[length-1] EQ '\n') s[length-1] = NULL;
return(1);
}
/*--------------------------------------------------------------------